package cn.yuanqiao.web.controller.archive.Identify;/**
 * @author 赵常飞
 * @date 2023/7/10 10:16
 */

import cn.yuanqiao.archive.Identify.domain.YqMjApprove;
import cn.yuanqiao.archive.Identify.service.IMjIdentifyService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @AUTHOR:赵常飞
 * @date 2023/7/10 10:16
 */
@RestController
@RequestMapping("/archive/mjidentify")
public class MjIdentifyController extends BaseController {
    @Autowired
    private IMjIdentifyService mjIdentifyService;

    @PreAuthorize("@ss.hasPermi('archive:mjidentify:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody JSONObject json) {
        List<Map<String, Object>> list = mjIdentifyService.getlist(json,"1");
        return getDataTable(list);
    }

    /**
     * 审批通过后修改密级状态
     *
     * @param id
     * @return
     */
    @Log(title = "密级审批通过", businessType = BusinessType.UPDATE)
    @PutMapping("/update/pass/state")
    public AjaxResult updateMjType(@RequestBody String id) {
        return toAjax(mjIdentifyService.updateMjType(id));
    }

    /**
     * 密级审批不通过
     *
     * @param id
     * @return
     */
    @Log(title = "密级审批不通过", businessType = BusinessType.UPDATE)
    @PutMapping("/update/disagree/state")
    public AjaxResult disagreeMjType(@RequestBody String id) {
        return toAjax(mjIdentifyService.disagreeMjType(id));
    }

    /**
     * 取消密级审批
     *
     * @param id
     * @return
     */
    @Log(title = "取消密级审批", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel/approval")
    public AjaxResult cancelApproval(@RequestBody String id) {
        return toAjax(mjIdentifyService.cancelApproval(id));
    }

    /**
     * 查询审批详情
     *
     * @param id
     * @return
     */
    @Log(title = "查询审批详情", businessType = BusinessType.UPDATE)
    @PostMapping("/initiate/approval")
    public AjaxResult initiateApproval(@RequestBody String id) {
        return AjaxResult.success(mjIdentifyService.initiateApproval(id));
    }

    /**
     * 查询审批详情
     *
     * @param instanceId
     * @return
     */
    @PostMapping("/initiate/getInfoByInstanceId/{instanceId}")
    public AjaxResult getInfoByInstanceId(@PathVariable("instanceId") String instanceId) {
        YqMjApprove yqMjApproveByInstanceId = mjIdentifyService.getYqMjApproveByInstanceId(instanceId);
        return AjaxResult.success(mjIdentifyService.initiateApproval(yqMjApproveByInstanceId.getId()));

    }

    /**
     * 添加到密级审批
     *
     * @param yqMjApprove
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:mjidentify:cancelApproval')")
    @Log(title = "添加到密级审批", businessType = BusinessType.INSERT)
    @PostMapping("/cancel/approval")
    public AjaxResult cancelApproval(@RequestBody List<YqMjApprove> yqMjApprove) {
        return toAjax(mjIdentifyService.insMjType(yqMjApprove));
    }

    /**
     * 查询密级审批列表
     *
     * @param yqMjApprove
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:mjidentify:approveList')")
    @PostMapping("approve/list")
    public TableDataInfo YqMjApproveList(@RequestBody YqMjApprove yqMjApprove) {
        startPage();
        List<YqMjApprove> list = mjIdentifyService.YqMjApproveList(yqMjApprove);
        return getDataTable(list);
    }

}
